package com.gitee.neuray.security.generator.config;

import com.gitee.neuray.security.auth.client.interceptor.ServiceAuthRestInterceptor;
import com.gitee.neuray.security.auth.client.interceptor.UserAuthRestInterceptor;
import com.gitee.neuray.security.common.handler.GlobalExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.Collections;

/**
 * springmvc适配器
 * @author zhhongyu
 * @date 2020年1月8号
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
    @Bean
    GlobalExceptionHandler getGlobalExceptionHandler() {
        return new GlobalExceptionHandler();
    }

    /**
     * 所有请求拦截
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(getServiceAuthRestInterceptor())
//                .addPathPatterns("/code/**");
        registry.addInterceptor(getUserAuthRestInterceptor()).
                addPathPatterns("/code/**");
    }

    @Bean
    ServiceAuthRestInterceptor getServiceAuthRestInterceptor() {
        return new ServiceAuthRestInterceptor();
    }

    @Bean
    UserAuthRestInterceptor getUserAuthRestInterceptor() {
        return new UserAuthRestInterceptor();
    }


}
